/**
 */
package ms.unicorn.dsl.unicornDSL.impl;

import ms.unicorn.dsl.unicornDSL.UnicornDSLPackage;
import ms.unicorn.dsl.unicornDSL.XExpression;
import ms.unicorn.dsl.unicornDSL.XMemberTerm;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>XMember Term</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link ms.unicorn.dsl.unicornDSL.impl.XMemberTermImpl#getOwner <em>Owner</em>}</li>
 *   <li>{@link ms.unicorn.dsl.unicornDSL.impl.XMemberTermImpl#isNullSafe <em>Null Safe</em>}</li>
 *   <li>{@link ms.unicorn.dsl.unicornDSL.impl.XMemberTermImpl#getMember <em>Member</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class XMemberTermImpl extends XExpressionImpl implements XMemberTerm
{
  /**
   * The cached value of the '{@link #getOwner() <em>Owner</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getOwner()
   * @generated
   * @ordered
   */
  protected XExpression owner;

  /**
   * The default value of the '{@link #isNullSafe() <em>Null Safe</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isNullSafe()
   * @generated
   * @ordered
   */
  protected static final boolean NULL_SAFE_EDEFAULT = false;

  /**
   * The cached value of the '{@link #isNullSafe() <em>Null Safe</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isNullSafe()
   * @generated
   * @ordered
   */
  protected boolean nullSafe = NULL_SAFE_EDEFAULT;

  /**
   * The cached value of the '{@link #getMember() <em>Member</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getMember()
   * @generated
   * @ordered
   */
  protected XExpression member;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected XMemberTermImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return UnicornDSLPackage.Literals.XMEMBER_TERM;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public XExpression getOwner()
  {
    return owner;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetOwner(XExpression newOwner, NotificationChain msgs)
  {
    XExpression oldOwner = owner;
    owner = newOwner;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, UnicornDSLPackage.XMEMBER_TERM__OWNER, oldOwner, newOwner);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setOwner(XExpression newOwner)
  {
    if (newOwner != owner)
    {
      NotificationChain msgs = null;
      if (owner != null)
        msgs = ((InternalEObject)owner).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - UnicornDSLPackage.XMEMBER_TERM__OWNER, null, msgs);
      if (newOwner != null)
        msgs = ((InternalEObject)newOwner).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - UnicornDSLPackage.XMEMBER_TERM__OWNER, null, msgs);
      msgs = basicSetOwner(newOwner, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, UnicornDSLPackage.XMEMBER_TERM__OWNER, newOwner, newOwner));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isNullSafe()
  {
    return nullSafe;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setNullSafe(boolean newNullSafe)
  {
    boolean oldNullSafe = nullSafe;
    nullSafe = newNullSafe;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, UnicornDSLPackage.XMEMBER_TERM__NULL_SAFE, oldNullSafe, nullSafe));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public XExpression getMember()
  {
    return member;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetMember(XExpression newMember, NotificationChain msgs)
  {
    XExpression oldMember = member;
    member = newMember;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, UnicornDSLPackage.XMEMBER_TERM__MEMBER, oldMember, newMember);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setMember(XExpression newMember)
  {
    if (newMember != member)
    {
      NotificationChain msgs = null;
      if (member != null)
        msgs = ((InternalEObject)member).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - UnicornDSLPackage.XMEMBER_TERM__MEMBER, null, msgs);
      if (newMember != null)
        msgs = ((InternalEObject)newMember).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - UnicornDSLPackage.XMEMBER_TERM__MEMBER, null, msgs);
      msgs = basicSetMember(newMember, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, UnicornDSLPackage.XMEMBER_TERM__MEMBER, newMember, newMember));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case UnicornDSLPackage.XMEMBER_TERM__OWNER:
        return basicSetOwner(null, msgs);
      case UnicornDSLPackage.XMEMBER_TERM__MEMBER:
        return basicSetMember(null, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case UnicornDSLPackage.XMEMBER_TERM__OWNER:
        return getOwner();
      case UnicornDSLPackage.XMEMBER_TERM__NULL_SAFE:
        return isNullSafe();
      case UnicornDSLPackage.XMEMBER_TERM__MEMBER:
        return getMember();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case UnicornDSLPackage.XMEMBER_TERM__OWNER:
        setOwner((XExpression)newValue);
        return;
      case UnicornDSLPackage.XMEMBER_TERM__NULL_SAFE:
        setNullSafe((Boolean)newValue);
        return;
      case UnicornDSLPackage.XMEMBER_TERM__MEMBER:
        setMember((XExpression)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case UnicornDSLPackage.XMEMBER_TERM__OWNER:
        setOwner((XExpression)null);
        return;
      case UnicornDSLPackage.XMEMBER_TERM__NULL_SAFE:
        setNullSafe(NULL_SAFE_EDEFAULT);
        return;
      case UnicornDSLPackage.XMEMBER_TERM__MEMBER:
        setMember((XExpression)null);
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case UnicornDSLPackage.XMEMBER_TERM__OWNER:
        return owner != null;
      case UnicornDSLPackage.XMEMBER_TERM__NULL_SAFE:
        return nullSafe != NULL_SAFE_EDEFAULT;
      case UnicornDSLPackage.XMEMBER_TERM__MEMBER:
        return member != null;
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (nullSafe: ");
    result.append(nullSafe);
    result.append(')');
    return result.toString();
  }

} //XMemberTermImpl
